package com.huayue.task;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.huayue.service.RoomPredictOrderService;
import com.huayue.service.RoomStatusService;
import com.huayue.util.AuthCodeDB;
import com.huayue.util.OrderNumberHelper;

/**
 * 系统定时器
 */
@Component
public class SystemTask {

    @Autowired
    RoomPredictOrderService svc;

    @Autowired
    RoomStatusService rsSvc;

    /**
     * 每天中午12点执行
     */
    @Scheduled(cron = "0 0 12 * * ?")
    public void PredictOrderTaskJob() {
        // 1.更改已预定未入住的房间状态更改为空房
        int i = svc.updatePredictOrderNotCheckIn();
        System.out.println(new Date() + "处理未入住订单" + i + "条");
        // 2.今日退房的房间强制退房
        int j = rsSvc.updateForceQuitAUTO();
        System.out.println(new Date() + "强制退房共" + j + "间");
    }

    /**
     * 每天中午13点执行
     */
    @Scheduled(cron = "0 0 13 * * ?")
    public void StatusTaskJob() {
        // 1.将今日预约的房间状态更改为预定
        int i = svc.updateRoomStatusByPredictAUTO();
        System.out.println(new Date() + "预定房共" + i + "间");
    }

    /**
     * 每天23:59:59执行清空临时订单
     */
    @Scheduled(cron = "59 59 23 * * ?")
    public void OrderNumberTaskJob() {

        OrderNumberHelper.JHDORDER.clear();
        OrderNumberHelper.CKDORDER.clear();
        OrderNumberHelper.RKDORDER.clear();
        OrderNumberHelper.YDDORDER.clear();
        OrderNumberHelper.XSDORDER.clear();
        // OrderNumberHelper.ZFBORDER.clear();
        OrderNumberHelper.FWORDER.clear();
        OrderNumberHelper.RZDORDER.clear();
        System.out.println(new Date() + "临时订单号已清空");
    }

    /**
     * 每天23:59:59执行清空手机验证码
     */
    @Scheduled(cron = "59 59 23 * * ?")
    public void AuthCodeDBTaskJob() {
        AuthCodeDB.AUTHCODEDB.clear();
        System.out.println(new Date() + "手机验证码已清空");
    }

    /**
     * 每天0:1:1执行将今日退房的客房状态改为待退 quit=1
     */
    @Scheduled(cron = "1 1 0 * * ?")
    public void RoomStatusToQuitTaskJob() {
        int i = rsSvc.updateQuitRoom();
        System.out.println(new Date() + "待退房共" + i + "间");
    }
}
